<?php

namespace app\admin\model;

use think\Model;


class Information extends Model
{

    

    

    // 表名
    protected $name = 'information';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'projecttype_text'
    ];
    

    
    public function getTypeList()
    {
        return ['通知' => __('通知'), '指南' => __('指南'), '项目征集' => __('项目征集')];
    }

    public function getProjecttypeList()
    {
        return ['' => __(''), 'A' => __('A'), 'B' => __('B')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getProjecttypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['projecttype']) ? $data['projecttype'] : '');
        $list = $this->getProjecttypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getInfoList($cid)
    {
        if(empty($cid))
        {
            $cat='通知';
        }
        if($cid==1) $cat = '通知';
        if($cid==2) $cat = '指南';
        if($cid==3) $cat = '项目征集';
        return Information::where('type','=',$cat)->order('id', 'desc')->paginate(9);
    }
    public function getInfo($id)
    {
        return Information::where('id','=',$id)->find();
    }


}
